import sys
from PyQt5.QtGui import QIcon
from Wang import *
from PyQt5.QtWidgets import QApplication, QMainWindow
import ctypes
ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID("myappid")


class WangWindow(QMainWindow):
    def __init__(self):
        super().__init__()
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)
        self.setWindowFlags(QtCore.Qt.FramelessWindowHint)
        self.setAttribute(QtCore.Qt.WA_TranslucentBackground)
        # self.ui.pushButton_2.clicked.connect(self.restore_or_maxmize_window)
        self.ui.pushButton_15.clicked.connect(lambda: self.ui.stackedWidget.setCurrentIndex(0))
        self.ui.pushButton_16.clicked.connect(lambda: self.ui.stackedWidget.setCurrentIndex(1))
        self.ui.pushButton_17.clicked.connect(lambda: self.ui.stackedWidget.setCurrentIndex(2))
        self.ui.pushButton_19.clicked.connect(lambda: self.ui.stackedWidget.setCurrentIndex(4))
        self.ui.pushButton_18.clicked.connect(lambda: self.ui.stackedWidget.setCurrentIndex(3))
        self.show()

    def mousePressEvent(self, event):
        if event.button() == QtCore.Qt.LeftButton and self.isMaximized() == False:
            self.m_flag = True
            self.m_Position = event.globalPos() - self.pos()  # 获取鼠标相对窗口的位置
            event.accept()
            self.setCursor(QtGui.QCursor(QtCore.Qt.OpenHandCursor))  # 更改鼠标图标

    def mouseMoveEvent(self, mouse_event):
        if QtCore.Qt.LeftButton and self.m_flag:
            self.move(mouse_event.globalPos() - self.m_Position)  # 更改窗口位置
            mouse_event.accept()

    def mouseReleaseEvent(self, mouse_event):
        self.m_flag = False
        self.setCursor(QtGui.QCursor(QtCore.Qt.ArrowCursor))

    #
    def restore_or_maxmize_window(self):  # 放大缩小
        if self.isMaximized():
            self.showNormal()
            self.ui.pushButton_2.setIcon(QtGui.QIcon(":\\"))
        else:
            self.showMaximized()
            self.ui.pushButton_2.setIcon(QtGui.QIcon(":\\"))


if __name__ == '__main__':
    app = QApplication(sys.argv)
    win = WangWindow()
    # ui = Ui_MainWindow()
    # ui.setupUi(win)
    # win.show()
    win.setWindowTitle(u'网易云')
    win.setWindowIcon(QIcon('01.png'))
    sys.exit(app.exec_())
